#nullable enable
using System.ComponentModel.DataAnnotations;
using SqlSugar;

namespace FytSoa.Domain.Sys;

/// <summary>
/// 用户账号信息，包含登录口令等敏感字段。
/// </summary>
[SugarTable("sys_user_account")]
public class SysUserAccount
{
    /// <summary>
    /// 主键：用户ID。
    /// </summary>
    [SugarColumn(ColumnName = "id", IsPrimaryKey = true)]
    public long Id { get; set; }

    /// <summary>
    /// 租户ID。
    /// </summary>
    [Required]
    [SugarColumn(ColumnName = "tenant_id")]
    public long TenantId { get; set; }

    /// <summary>
    /// 登录名（租户内唯一）。
    /// </summary>
    [Required]
    [StringLength(100)]
    [SugarColumn(ColumnName = "user_name")]
    public string UserName { get; set; } = string.Empty;

    /// <summary>
    /// 显示名称。
    /// </summary>
    [Required]
    [StringLength(200)]
    [SugarColumn(ColumnName = "display_name")]
    public string DisplayName { get; set; } = string.Empty;

    /// <summary>
    /// 邮箱，可选。
    /// </summary>
    [StringLength(200)]
    [SugarColumn(ColumnName = "email")]
    public string? Email { get; set; }

    /// <summary>
    /// 手机，可选。
    /// </summary>
    [StringLength(50)]
    [SugarColumn(ColumnName = "phone")]
    public string? Phone { get; set; }

    /// <summary>
    /// 密码哈希。
    /// </summary>
    [Required]
    [StringLength(255)]
    [SugarColumn(ColumnName = "password_hash")]
    public string PasswordHash { get; set; } = string.Empty;

    /// <summary>
    /// 密码算法。
    /// </summary>
    [Required]
    [StringLength(32)]
    [SugarColumn(ColumnName = "password_algo")]
    public string PasswordAlgo { get; set; } = "argon2id";

    /// <summary>
    /// 密码最近更新时间。
    /// </summary>
    [SugarColumn(ColumnName = "password_updated_at")]
    public DateTime PasswordUpdatedAt { get; set; }

    /// <summary>
    /// 是否要求下次登录改密。
    /// </summary>
    [SugarColumn(ColumnName = "must_change_password")]
    public bool MustChangePassword { get; set; }

    /// <summary>
    /// 是否启用。
    /// </summary>
    [SugarColumn(ColumnName = "is_active")]
    public bool IsActive { get; set; } = true;

    /// <summary>
    /// 是否锁定。
    /// </summary>
    [SugarColumn(ColumnName = "is_locked")]
    public bool IsLocked { get; set; }

    /// <summary>
    /// 连续失败登录次数。
    /// </summary>
    [SugarColumn(ColumnName = "failed_login_count")]
    public int FailedLoginCount { get; set; }

    /// <summary>
    /// 最近登录时间。
    /// </summary>
    [SugarColumn(ColumnName = "last_login_at")]
    public DateTime? LastLoginAt { get; set; }

    /// <summary>
    /// 最近登录IP。
    /// </summary>
    [StringLength(64)]
    [SugarColumn(ColumnName = "last_login_ip")]
    public string? LastLoginIp { get; set; }

    /// <summary>
    /// 创建时间。
    /// </summary>
    [SugarColumn(ColumnName = "created_at")]
    public DateTime CreatedAt { get; set; }

    /// <summary>
    /// 更新时间。
    /// </summary>
    [SugarColumn(ColumnName = "updated_at")]
    public DateTime UpdatedAt { get; set; }
}
